package com.lineage.data.item_etcitem.shop;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class TimeUpdate1 extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(TimeUpdate1.class);
  
  public static ItemExecutor get() {
    return new TimeUpdate1();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (item == null)
      return; 
    if (pc == null)
      return; 
    try {
      int targObjId = data[0];
      L1ItemInstance tgItem = pc.getInventory().getItem(targObjId);
      if (tgItem == null)
        return; 
      if (tgItem.getItem().getType2() == 0) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
        return;
      } 
      if (tgItem.getItem().getMaxUseTime() <= 0) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
        return;
      } 
      pc.getInventory().removeItem(item, 1L);
      int time = tgItem.getItem().getMaxUseTime();
      tgItem.setRemainingTime(time);
      pc.getInventory().updateItem(tgItem, 256);
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
